import { AllSkillKey, SkillLearnType } from "../../config/SkillConfig";
import L_Run from "../../utils/L_Run";

/**管理单位已学技能的管理类 只做一个简单关联类使用 因为技能等级是与玩家绑定的  */
export default class HeroLearnSkill{
 
  public learnSkillMap:Map<SkillLearnType,AllSkillKey> = new Map();
 
  public heroUnit:unit;
 
  constructor(heroUnit:unit){
    this.heroUnit=heroUnit;           
  }

  /**刷新,同步英雄的类型技能和玩家管理的技能map数据一致  类型技能+等级(使用于改变技能的情况) */
  public syncTypeSkill(skillIdStr:AllSkillKey,skillLvl:number,skillLearnType:SkillLearnType){
    let hisTypeSkillId= this.learnSkillMap.get(skillLearnType)
    console.log("英雄",this.heroUnit,"技能槽位[",skillLearnType,"]技能从",hisTypeSkillId,"变更为",skillIdStr)
    if(hisTypeSkillId!=undefined && hisTypeSkillId!=skillIdStr){
        //删除旧的  添加新的
        L_Run.UnitRemoveAbility(this.heroUnit,hisTypeSkillId)
        L_Run.UnitAddAbilityWithLvl(this.heroUnit,skillIdStr,skillLvl)
    }else{
        //该位置无技能 添加新的
        L_Run.UnitAddAbilityWithLvl(this.heroUnit,skillIdStr,skillLvl)
    }
    //刷新
    this.learnSkillMap.set(skillLearnType,skillIdStr);
  }

  /**刷新,同步英雄的类型技能和玩家管理的技能lvl一致  玩家某个技能等级提升了 所有关联单位等级同步刷新的意思 */
  public syncTypeSkillLvl(skillIdStr:AllSkillKey,skillLvl:number,skillLearnType:SkillLearnType){
    if(this.learnSkillMap.get(skillLearnType)==skillIdStr){
      L_Run.UnitSetAbilityLvl(this.heroUnit,skillIdStr,skillLvl)
    }
  }

  /**判断单位是否学习了某个技能 方便执行同步刷新动作 */
  // public heroLearndSkill(skillLearnType:SkillLearnType,skillIdStr:AllSkillKey){
  //   return this.learnSkillMap.get(skillLearnType)==skillIdStr
  // }

  
}  